﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;

namespace org.swinchester.windowsevents.mongodb
{
    public abstract class MongoDaoBase
    {
        protected MongoDatabase mongoDb;
        protected MongoDbConfig config;

        public MongoDbConfig MongoDbConfig
        {
            set { this.config = value; }
        }

        protected MongoDatabase GetMongoDb()
        {
            if (mongoDb == null)
            {
                var server = MongoServer.Create(config.ConnectionString);
                mongoDb = server.GetDatabase(config.Database);
                return mongoDb;
            }
            else
            {
                return mongoDb;
            }
        }
    }
}
